﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace Aliyun.SmsSdk.AspNetCore
{
    public static class AliyunSmsServiceCollectionExtensions
    {
        public static IServiceCollection AddAliyunSms(this IServiceCollection services, Action<AliyunSmsOptions> options)
        {
            if (services == null)
                throw new ArgumentNullException(nameof(services));
            if (options == null)
                throw new ArgumentNullException(nameof(options));
            services.AddOptions();
            services.Configure(options);
            services.Add(ServiceDescriptor.Transient<IAliyunSmsService, AliyunSmsService>());

            return services;
        }

        public static IServiceCollection AddAliyunSms(this IServiceCollection services, IConfiguration configs)
        {
            if (services == null)
                throw new ArgumentNullException(nameof(services));
            if (configs == null)
                throw new ArgumentNullException(nameof(configs));
            services.AddOptions();
            services.Configure<AliyunSmsOptions>(configs);
            services.AddScoped<AliyunSmsService>();
            return services;
        }
    }
}
